const express = require("express");
const router = express.Router();
const dayjs = require("dayjs");
let connectDAO = require("./connect.js");

router.post("/catch_vue_error", function (req, res) {
  const { errorMsg } = req.body;
  const registerTime = dayjs().format('YYYY-MM-DD HH:mm:ss');
  const insertsql = `INSERT INTO vue_error VALUES ('${registerTime}', '${errorMsg}')`;
  function processData() {
    connectDAO
      .queryDataBySQL(insertsql)
      .then(() => {
        res.send({ code: 200, msg: "catch" });
      })
      .catch((err) => {
        res.send({ code: 201, msg: "catch failed!" + err });
      });
  }
  processData();
});

module.exports = router;
